<template>
  <div>
    <van-tabs v-model="active" @click="change">
      <van-tab
      v-for="(item,index,) in tab"
      :key="index"
      :title="item.title"
      :name="item.tab"
      ></van-tab>
    </van-tabs>
    <applist :list="list"></applist>
  </div>
</template>

<script>
import applist from './applist';
export default {
    components:{
        applist

    },
    data() {
        return {
            active:localStorage.getItem('tab')||"share",
            tab:[{
                title:"全部",tab:"all"
            },{
                title:"精华",tab:"pure"
            },{
                title:"分享",tab:"share"
            },{
                title:"问答",tab:"ask"
            },{
                title:"招聘",tab:"order"
            },{
                title:"客户端",tab:"user"
            },],
            list:[],
        };
    },
    mounted() {
        this.change();
    },
    methods: {
        change(tab){
            localStorage.setItem("tab",this.active);
            this.list=[],
            this.$http("/list.json","get").then((res)=>{
                console.log(res);
                res.data.forEach((item)=>{
                    if(item.tab==this.active){
                        this.list.push(item);
                    }
                });
            });
        },
    },
};
</script>